import {
  userslist,
  creatusers,
  removeusers,
  updateusers,
  queryUsers,
  exportOperatorList,
  resetpassword
} from '../services/users';

export default {
  namespace: 'users',

  state: {
    list: [],
    currentUsers: [],
  },

  effects: {
    //读者证信息列表
    *getUserslist(_, { call, put }) {
      const response = yield call(userslist);
      yield put({
        type: 'saveCurrenUsers',
        payload: response,
      });
    },
     //查详情信息
    *orgdetail({ payload: id }, { call, put }) {
      const response = yield call(orgDetail, id);
      yield put({
        type: 'saveDetailOrg',
        payload: response,
      });
    },
    //删除读者证信息
    *remove({ payload: id }, { call, put }) {
      yield call(removeusers, id);
      yield put({ type: 'getUserslist' });
    },
    //修改组织信息
    *update({ payload: { id, values } }, { call, put }) {
      yield call(updateusers, id, values);
      yield put({ type: 'getUserslist' });
    },
    //修改组织信息
    *reset({ payload: { id, values } }, { call, put }) {
        yield call(resetpassword, id, values);
        yield put({ type: 'getUserslist' });
      },
    //增加信息
    *create({ payload: values }, { call, put }) {
    const response = yield call(creatusers, values);
    yield put({ type: 'getUserslist' });
  },
    //检索
    *fetch({ payload }, { call, put }) {
      const response = yield call(queryUsers, payload);
      yield put({
        type: 'saveCurrenUsers',
        payload: response,
      });
    }, 
    /* //查详情信息
    *carddetail({ payload: id }, { call, put }) {
      const response = yield call(cardDetail, id);
      yield put({
        type: 'saveDetailCard',
        payload: response,
      });
    },
    //增加读者证信息
    *create({ payload: values }, { call, put }) {
      const response = yield call(creatcard, values);
      yield put({ type: 'getCardlist' });
    },
    //删除读者证信息
    *remove({ payload: id }, { call, put }) {
      yield call(removecard, id);
      yield put({ type: 'getCardlist' });
    },
    //修改人员信息
    *update({ payload: { id, values } }, { call, put }) {
      yield call(updateCard, id, values);
      yield put({ type: 'getCardlist' });
    }, 
    //检索
    *fetch({ payload }, { call, put }) {
      console.log(payload)
      const response = yield call(queryCard, payload);
      yield put({
        type: 'saveCurrentCard',
        payload: response,
      });
    }, */
  },

  reducers: {
    /*     save(state, action) {
      return {
        ...state,
        list: action.payload,
      };
    }, */
    saveCurrenUsers(state, action) {
      return {
        ...state,
        currentUsers: action.payload,
      };
    },

    changeNotifyCount(state, action) {
      return {
        ...state,
        currentUsers: {
          ...state.currentUsers,
          notifyCount: action.payload,
        },
      };
    },
  },
};
